//
//  QYGDetailCatchCell.m
//  wawaji_ios
//
//  Created by 奇艺果 on 2017/12/29.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGDetailCatchCell.h"

@interface QYGDetailCatchCell()

@property (nonatomic, strong) UIImageView *headerView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *arrowLabel;
@property (nonatomic, strong) UIView *lineView;

@end


@implementation QYGDetailCatchCell

- (void)drollRecordCellWithIconStr:(NSString *)iconStr nameStr:(NSString *)nameStr detailStr:(NSString *)detailStr arrowResult:(NSInteger)arrowResult{
    _iconStr = iconStr;
    _nameStr = nameStr;
    _detailStr = detailStr;
    _arrowStr = arrowResult == 1 ? @"抓取成功":@"抓取失败";
    
    [self.headerView setImageURL:[NSURL URLWithString:iconStr]];
    self.nameLabel.text = nameStr;
    self.detailLabel.text = detailStr;
    self.arrowLabel.text = _arrowStr;
    self.arrowLabel.textColor = arrowResult != 1 ?[UIColor colorWithHex:@"999999"] :[UIColor colorWithHex:@"29c956"];
    
    
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
    [self.arrowLabel sizeToFit];
}
- (void)setDetailStr:(NSString *)detailStr{
    _detailStr = detailStr;
    self.detailLabel.text = detailStr;
    [self.detailLabel sizeToFit];
    
}
- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.nameLabel.text = nameStr;
    [self.nameLabel sizeToFit];
}
- (void)setIconStr:(NSString *)iconStr{
    _iconStr = iconStr;
    [self.headerView setImageURL:[NSURL URLWithString:iconStr]];
}

- (void)setArrowStr:(NSString *)arrowStr{
    
    _arrowStr = arrowStr;
    self.arrowLabel.text = arrowStr;
    [self.arrowLabel sizeToFit];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.headerView.x = ScaleW(15);
    self.headerView.y = (self.height - self.headerView.height) * 0.5;
    
    self.nameLabel.y = self.headerView.y + ScaleW(5);
    self.nameLabel.x = CGRectGetMaxX(self.headerView.frame) + ScaleW(14);
    self.nameLabel.width = self.width - self.nameLabel.x - ScaleW(70);
    
    self.detailLabel.y = CGRectGetMaxY(self.nameLabel.frame) + ScaleW(10);
    self.detailLabel.x = self.nameLabel.x;
    
    self.arrowLabel.y = self.nameLabel.y;
    self.arrowLabel.x = self.width - self.arrowLabel.width - ScaleW(15);
    
    self.lineView.x = ScaleW(15);
    self.lineView.height = ScaleW(1);
    self.lineView.width = self.width - 2 * ScaleW(15);
    self.lineView.y = self.height - ScaleW(1);
}
#pragma mark - setUI

- (void)setupUI{
    [self addSubview:self.headerView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
    [self addSubview:self.arrowLabel];
    [self addSubview:self.lineView];
}

#pragma mark lazy

- (UILabel *)arrowLabel{
    
    if(!_arrowLabel){
        _arrowLabel = [UILabel labelWithText:@"抓取1次" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment:NSTextAlignmentRight];
        _arrowLabel.size = CGSizeMake(ScaleW(200), ScaleW(20));
        _arrowLabel.numberOfLines = 1;
    }
    return _arrowLabel;
}


- (UILabel *)detailLabel{
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"22小时88分99秒前 " setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment:NSTextAlignmentLeft];
        //        [_nameLabel sizeToFit];
        _detailLabel.numberOfLines = 1;
        
    }
    return _detailLabel;
}
- (UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel labelWithText:@"抓取用户 " setFont:ScaleFont(14) setTextColor:[UIColor colorWithHex:@"333333"] setTextAlignment:NSTextAlignmentLeft];
        _nameLabel.numberOfLines = 1;
        
    }
    return _nameLabel;
}
- (UIImageView *)headerView{
    if(!_headerView){
        _headerView = [[UIImageView alloc] init];
        _headerView.size = CGSizeMake(ScaleW(50), ScaleW(50));
        _headerView.layer.cornerRadius = ScaleW(25);
        _headerView.layer.masksToBounds = YES;
        
    }
    return _headerView;
}

- (UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithHex:@"e1e4eb"];
    }
    return _lineView;
}
@end
